package com.lovo.invoicing.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lovo.invoicing.bean.ClientBean;
import com.lovo.invoicing.bean.PageBean;
import com.lovo.invoicing.service.IClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/client")
public class ClientController {
    @Autowired
    IClientService clientService;
    @RequestMapping("/addClient")
    public String addClient(@RequestBody ClientBean clientBean){
        clientService.addClient(clientBean);
        return "success";
    }

    @RequestMapping("/findClientById")
    public ClientBean findClientById(int clientId){
        return clientService.queryClientById(clientId);
    }

    @RequestMapping("/modifyClient")
    public String modifyClient(@RequestBody ClientBean clientBean){
        clientService.updateClient(clientBean);
        return "success";
    }

    @RequestMapping("/findClientsByPage")
    public IPage<ClientBean> findClientsByPage(@RequestBody PageBean<ClientBean> pageBean){
        return clientService.queryClientsByPage(pageBean);
    }

    @RequestMapping("/findAllClients")
    public List<ClientBean> findAllClients(){
        return clientService.queryAllClients();
    }
}
